package com.imti.mall.product.mapper;

import com.imti.mall.model.pms.pojo.PmsBrand;
import com.imti.mall.model.pms.pojo.PmsProductAttribute;
import com.imti.mall.model.pms.pojo.PmsProductAttributeCategory;
import com.imti.mall.model.pms.vo.PmsProductAttributeVo;
import org.apache.ibatis.jdbc.SQL;

/**
 * ClassName: PmsProductAttribute
 * Description:
 * date: 2022/9/13 13:54
 *
 * @author: youhun
 * @version:
 * @since JDK 1.8
 */

public class PmsProductAttributeDynaSqlProvider {


    public String updatePmsProductAttribute(final PmsProductAttributeVo pmsProductAttribute){
        return new SQL(){
            {
                UPDATE(" `pms_product_attribute` ");
                if(pmsProductAttribute.getProductAttributeCategoryId()!=null){
                    SET(" product_attribute_category_id=#{productAttributeCategoryId} ");
                }
                if(pmsProductAttribute.getName()!=null){
                    SET(" name=#{name} ");
                }
                if(pmsProductAttribute.getSelectType()!=null){
                    SET(" select_type=#{selectType} ");
                }
                if(pmsProductAttribute.getInputType()!=null){
                    SET(" input_type=#{inputType} ");
                }
                if(pmsProductAttribute.getInputList()!=null){
                    SET(" input_list=#{inputList} ");
                }
                if(pmsProductAttribute.getSort()!=null){
                    SET(" sort=#{sort} ");
                }
                if(pmsProductAttribute.getFilterType()!=null){
                    SET(" filter_type=#{filterType} ");
                }
                if(pmsProductAttribute.getSearchType()!=null){
                    SET(" search_type=#{searchType} ");
                }
                if(pmsProductAttribute.getRelatedStatus()!=null){
                    SET(" related_status=#{relatedStatus} ");
                }
                if(pmsProductAttribute.getHandAddStatus()!=null){
                    SET(" hand_add_status=#{handAddStatus} ");
                }
                if(pmsProductAttribute.getType()!=null){
                    SET(" type=#{type} ");
                }
                WHERE(" id=#{id} ");
            }
        }.toString();
    }



    /**
     * 动态查询sql
     * @param pmsProductAttribute
     * @return
     */
    public String findPmsProductAttribute(PmsProductAttribute pmsProductAttribute){
        return new SQL(){
            {
                SELECT(" id,product_attribute_category_id,NAME,select_type,input_type,input_list,sort,filter_type,search_type,related_status,hand_add_status,TYPE ");
                FROM(" pms_product_attribute ");
                StringBuffer sb=new StringBuffer();
                if(pmsProductAttribute!=null) {
                    if (pmsProductAttribute.getProductAttributeCategoryId()!= null) {
                        sb.append(" and  product_attribute_category_id=#{productAttributeCategoryId}");
                    }
                    //按照是否为品牌制造商查找
                    if (pmsProductAttribute.getType()!= null) {
                        sb.append(" and  type=#{type}");
                    }
                    //根据上级分类的编号进行查询
                    if (pmsProductAttribute.getName() != null) {
                        sb.append(" and name  LIKE concat('%',#{name},'%')");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }

    /**
     * 动态查询sql
     * @param pmsProductAttribute
     * @return
     */
    public String getPmsProductAttribute(PmsProductAttribute pmsProductAttribute){
        return new SQL(){
            {
                SELECT(" count(*) ");
                FROM(" pms_product_attribute ");
                StringBuffer sb=new StringBuffer();
                if(pmsProductAttribute!=null) {
                    if (pmsProductAttribute.getProductAttributeCategoryId()!= null) {
                        sb.append(" and  product_attribute_category_id=#{productAttributeCategoryId}");
                    }
                    //按照是否为品牌制造商查找
                    if (pmsProductAttribute.getType()!= null) {
                        sb.append(" and  type=#{type}");
                    }
                    //根据上级分类的编号进行查询
                    if (pmsProductAttribute.getName() != null) {
                        sb.append(" and name  LIKE concat('%',#{name},'%')");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }
}
